<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>部门管理 - 企业资产管理系统</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.1/font/bootstrap-icons.css">
    <link  rel="stylesheet" type="text/css" href="/static/css/zc.css"></head>
<body>

<!-- 头部导航 -->
<header class="header">
    <div class="logo">
        <i class="bi bi-building"></i>
        <span>企业资产管理系统</span>
    </div>
    <div class="header-right">
        <div class="notification-icon">
            <i class="bi bi-bell"></i>
            <span class="notification-badge">3</span>
        </div>
        <div class="dropdown">
            <a href="#" class="dropdown-toggle" id="userDropdown" data-bs-toggle="dropdown" aria-expanded="false">
                <img src="https://cn.bing.com/images/search?view=detailV2&ccid=OSFH3hIu&id=6E8860BEADD760736BEA422E3C9BF57317AA4F3E&thid=OIP.OSFH3hIukHqh-qrOvIfUWgAAAA&mediaurl=https%3a%2f%2fc-ssl.dtstatic.com%2fuploads%2fblog%2f202303%2f20%2f20230320145706_07ca5.thumb.400_0.jpeg&exph=498&expw=400&q=%e5%a4%b4%e5%83%8f&simid=607997774809754286&FORM=IRPRST&ck=19ACE4792BC2347CFE89D1BC55CC90F4&selectedIndex=0&itb=0" class="rounded-circle user-avatar" alt="用户头像">
                <span>管理员</span>
                <i class="bi bi-chevron-down"></i>
            </a>
            <ul class="dropdown-menu dropdown-menu-end" aria-labelledby="userDropdown">
                <li><a class="dropdown-item" href="#"><i class="bi bi-person me-2"></i>个人信息</a></li>
                <li><a class="dropdown-item" href="#"><i class="bi bi-gear me-2"></i>系统设置</a></li>
                <li><hr class="dropdown-divider"></li>
                <li><a class="dropdown-item" href="#"><i class="bi bi-box-arrow-right me-2"></i>退出登录</a></li>
            </ul>
        </div>
    </div>
</header>

<!-- 主体内容 -->
<div class="main-container">
    <!-- 侧边栏 -->
    <aside class="sidebar">
        <ul class="sidebar-menu">
            <li class="sidebar-item">
                <a href="home.jsp" class="sidebar-link">
                    <i class="bi bi-speedometer2"></i>
                    <span>控制面板</span>
                </a>
            </li>
            <li class="sidebar-item">
                <a href="Inventory_Query.jsp" class="sidebar-link dropdown-toggle" data-bs-target="#assetMenu">
                    <i class="bi bi-laptop"></i>
                    <span>资产管理</span>
                    <i class="bi bi-chevron-down"></i>
                </a>
                <ul class="sidebar-dropdown collapse" id="assetMenu">
                    <li class="sidebar-item">
                        <a href="Inventory_Query.jsp" class="sidebar-link active">
                            <span>库存查询</span>
                        </a>
                    </li>
                    <li class="sidebar-item">
                        <a href="Asset_Inbound.jsp" class="sidebar-link">
                            <span>资产入库</span>
                        </a>
                    </li>
                    <li class="sidebar-item">
                        <a href="Asset_Scrap.jsp" class="sidebar-link">
                            <span>资产报废</span>
                        </a>
                    </li>
                </ul>
            </li>

            <li class="sidebar-item">
                <a href="Maintenance_Apply.jsp" class="sidebar-link dropdown-toggle" data-bs-target="#maintenanceMenu">
                    <i class="bi bi-tools"></i>
                    <span>维修管理</span>
                    <i class="bi bi-chevron-down"></i>
                </a>
                <ul class="sidebar-dropdown collapse" id="maintenanceMenu">
                    <li class="sidebar-item">
                        <a href="Maintenance_Apply.jsp" class="sidebar-link">
                            <span>维修申请</span>
                        </a>
                    </li>
                    <li class="sidebar-item">
                        <a href="maintenance_record.jsp" class="sidebar-link">
                            <span>维修记录</span>
                        </a>
                    </li>
                    <li class="sidebar-item">
                        <a href="maintenance_statistics.jsp" class="sidebar-link">
                            <span>维修统计</span>
                        </a>
                    </li>
                </ul>
            </li>

            <li class="sidebar-item">
                <a href="user_management.jsp" class="sidebar-link dropdown-toggle active" data-bs-target="#systemMenu">
                    <i class="bi bi-gear"></i>
                    <span>系统设置</span>
                    <i class="bi bi-chevron-down"></i>
                </a>
                <ul class="sidebar-dropdown collapse show" id="systemMenu">
                    <li class="sidebar-item">
                        <a href="user_management.jsp" class="sidebar-link">
                            <span>用户管理</span>
                        </a>
                    </li>
                    <li class="sidebar-item">
                        <a href="Department_Management.jsp" class="sidebar-link active">
                            <span>部门管理</span>
                        </a>
                    </li>
                </ul>
            </li>
        </ul>
    </aside>

    <!-- 内容区域 -->
    <main class="content">
        <h2 class="page-title">部门管理</h2>
        <div class="row">
            <div class="col-lg-12 mb-4">
                <div class="card">
                    <div class="card-header d-flex justify-content-between align-items-center">
                        <span>部门详情</span>
                        <button class="btn btn-sm btn-success">保存更改</button>
                    </div>
                    <div class="card-body">
                        <h5 class="mb-3">技术部信息</h5>
                        <form>
                            <div class="mb-3">
                                <label for="dept_name" class="form-label">部门名称</label>
                                <select class="form-select dept_name" id="dept_name" name="dept_id">
                                    <option value="0">请选择部门</option>
                                </select>
                            </div>
                            <div class="mb-3">
                                <label class="form-label">部门资产统计</label>
                                <div class="table-responsive">
                                    <table class="table">
                                        <thead>
                                            <tr>
                                                <th>资产类型</th>
                                                <th>数量</th>
                                                <th>价值</th>
                                            </tr>
                                        </thead>
                                        <tbody name="deptinfo">
                                            <tr>
                                                <td>固定资产</td>
                                                <td></td>
                                                <td></td>
                                            </tr>
                                            <tr>
                                                <td>无形资产</td>
                                                <td></td>
                                                <td></td>
                                            </tr>
                                            <tr>
                                                <td>其它资产</td>
                                                <td></td>
                                                <td></td>
                                            </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </main>
</div>

<!-- 页脚 -->
<footer class="footer">
    <div class="container">
        <div class="row">
            <div class="col-md-6">
                <span>版权所有 &copy; 2023 资产管理系统</span>
            </div>
            <div class="col-md-6 text-md-end">
                <span>技术支持：XXX公司</span>
            </div>
        </div>
    </div>
</footer>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script>
    // 等待DOM加载完成
    document.addEventListener('DOMContentLoaded', function() {
        // 初始化所有下拉菜单
        const dropdownElementList = [].slice.call(document.querySelectorAll('.dropdown-toggle'));
        dropdownElementList.map(function (dropdownToggleEl) {
            return new bootstrap.Dropdown(dropdownToggleEl);
        });

        // 获取所有带有dropdown-toggle类的链接
        const dropdownToggles = document.querySelectorAll('.sidebar-link.dropdown-toggle');

        // 为每个下拉菜单添加点击事件
        dropdownToggles.forEach(toggle => {
            toggle.addEventListener('click', function(e) {
                const href = this.getAttribute('href');
                
                // 如果有href属性且不是#或javascript:，则执行导航
                if (href && href !== '#' && !href.startsWith('javascript')) {
                    window.location.href = href;
                    return;
                }
                
                // 阻止默认行为
                e.preventDefault();

                // 获取目标菜单的ID
                const targetId = this.getAttribute('data-bs-target');
                const targetMenu = document.querySelector(targetId);

                // 获取当前菜单的箭头图标
                const arrowIcon = this.querySelector('.bi-chevron-down, .bi-chevron-up');

                // 切换目标菜单的显示状态
                if (targetMenu) {
                    const isShowing = targetMenu.classList.toggle('show');

                    // 根据显示状态更新箭头图标
                    if (arrowIcon) {
                        if (isShowing) {
                            arrowIcon.classList.remove('bi-chevron-down');
                            arrowIcon.classList.add('bi-chevron-up');
                        } else {
                            arrowIcon.classList.remove('bi-chevron-up');
                            arrowIcon.classList.add('bi-chevron-down');
                        }
                    }
                }

                // 关闭其他打开的下拉菜单
                document.querySelectorAll('.sidebar-dropdown').forEach(menu => {
                    if (menu !== targetMenu && menu.classList.contains('show')) {
                        menu.classList.remove('show');
                        // 重置其他菜单的箭头图标
                        const otherToggle = document.querySelector(`[data-bs-target="#${menu.id}"]`);
                        if (otherToggle) {
                            const otherArrow = otherToggle.querySelector('.bi-chevron-up');
                            if (otherArrow) {
                                otherArrow.classList.remove('bi-chevron-up');
                                otherArrow.classList.add('bi-chevron-down');
                            }
                        }
                    }
                });
            });
        });
    });
</script>
<script src="/static/jq/jquery-3.3.1.js"></script>
<script>
    $(function () {
        $.ajax({
            url: "/getDept",
            type: "get",
            dataType: "json",//   data:{"pageId":pageId},
            success: function (data) {
                console.log(data);
                $("#dept_name").children().not(":eq(0)").remove();
                for(var i = 0;i < data.length;i++){
                    $("#dept_name").append("<option value="+data[i].id+">--"+data[i].name+"--</option>")
                }
            }
        })
    })

    // $('#dept_name').click(function() {
    //     const formData = new FormData();
    //     formData.append('dept_name',$('#dept_name').val());
    //     $.ajax({
    //         url: "/getAssetDept",
    //         type: "get",
    //         dataType: "json",//   data:{"pageId":pageId},
    //         processData: false,  // 必须
    //         contentType: false,  // 必须
    //         cache: false,
    //         data: formData,
    //         success: function (map) {
    //             console.log("连表"+map.value);
    //             console.log("连表"+map.num);
    //         }
    //     })
    // })

    $(document).ready(function() {
            $('#dept_name').change(function() {
                // 获取选中的部门ID
                const deptId = $(this).val();
                console.log(deptId);
                // 通过name属性选择tbody元素
                const tbody = $('tbody[name="deptinfo"]');

                // 如果选择的是"请选择部门"选项（值为0）
                if (deptId == "0") {
                    tbody.hide(); // 隐藏表格
                    return;
                }

                $.ajax({
                    url: "/getAssetDept",
                    type: "get",
                    dataType: "json",//   data:{"pageId":pageId},
                    data: { dept_id: deptId }, // 发送部门ID作为参数
                    success: function (response) {
                        tbody.show(); // 显示表格

                        // 打印调试信息
                        console.log(response);
                        console.log("资产价值: " + response.dept_value);
                        console.log("资产数量: " + response.dept_num);
                        console.log("资产价值: " + response.dept_value1);
                        console.log("资产数量: " + response.dept_num1);
                        console.log("资产价值: " + response.dept_value2);
                        console.log("资产数量: " + response.dept_num2);
                        // 获取所有行
                        const rows = tbody.find('tr');

                        // 更新表格数据
                        // 第一行：固定资产
                        $(rows[0]).find('td').eq(1).text(response.dept_num+"个" || '');
                        $(rows[0]).find('td').eq(2).text(response.dept_value+"￥" || '');

                        // 第二行：无形资产
                        $(rows[1]).find('td').eq(1).text(response.dept_num1+"个" || '');
                        $(rows[1]).find('td').eq(2).text(response.dept_value1+"￥" || '');

                        // 第三行：其他资产
                        $(rows[2]).find('td').eq(1).text(response.dept_num2+"个" || '');
                        $(rows[2]).find('td').eq(2).text(response.dept_value2+"￥" || '');
                    }
                })
            })
        })

</script>



</body>
</html> 